<template>
  <div>
    <van-cell border>
      <van-image slot="icon" fit="cover" round :src=" com.photo" />
      <div slot="title">
        <div class="name-wrap">
          <span>{{com.aut_name}}</span>
          <div class="like" @click="onlikeClick">
            <van-icon :color=" com.is_liking ? 'pink':''  " :name=" com.is_liking ? 'good-job': 'good-job-o'" />
            <span> {{com.like_count}} </span></div>
        </div>
        <div class="content"> {{com.content}} </div>
        <div class="time"> <span>{{com.pubdate}} </span>
          <van-button plain type="info" round size='mini' @click="$emit('reply-click',com)" v-if="isShowBtn"> {{com.reply_count}} 回复</van-button>
        </div>
      </div>
    </van-cell>
  </div>
</template>
<script>
import { addCommentLike, deleteCommentLike } from '@/api/comment.js'
export default {
  name: 'commentIndex',
  props: {
    comment: {
      type: Object,
      required: true
    },
    isShowBtn: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      com: this.comment
    }
  },
  methods: {
    async onlikeClick() {
      if (this.com.is_liking) {
        await deleteCommentLike(this.com.com_id.toString())
        this.com.like_count--
      } else {
        await addCommentLike(this.com.com_id.toString())
        this.com.like_count++
      }
      this.com.is_liking = !this.com.is_liking
    }
  }
}
</script>
<style lang="less" scoped>
.van-cell {
  .name-wrap {
    display: flex;
    justify-content: space-between;
    > span {
      color: violet;
    }
  }
}
.like {
  display: flex;
  align-items: center;
}
.time {
  font-size: 10px;
  color: gray;
  .van-button {
    height: 20px;
    padding: 0 2px;
    margin-left: 10px;
  }
}

.van-image {
  width: 30px;
  height: 30px;
  margin-right: 10px;
}
.content {
  color: #333;
  font-size: 16px;
}
</style>
